#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int n, m, num;
int a[N], b[N];
vector<int> arr[N];

void solve() {
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];

  rep(i, 1, n) b[i] = a[i];
  sort(b + 1, b + n + 1);
  num = unique(b + 1, b + n + 1) - b - 1;
  rep(i, 1, n) a[i] = lower_bound(b + 1, b + num + 1, a[i]) - b;
  rep(i, 1, num) arr[i].clear();
  rep(i, 1, n) arr[a[i]].push_back(i);
  while (m--) {
    int L, R;
    cin >> L >> R;
    set<int> test;
    rep(i, 1, 50) {
      int id = mt() % (R + 1 - L) + L;
      test.insert(a[id]);
    }
    set<int> ans;
    for (int x : test) {
      int cnt = upper_bound(arr[x].begin(), arr[x].end(), R) -
                lower_bound(arr[x].begin(), arr[x].end(), L);
      if (cnt > (R + 1 - L) / 3) ans.insert(x);
    }
    if (ans.empty())
      cout << -1;
    else {
      for (int x : ans) cout << b[x] << ' ';
    }
    cout << endl;
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}